import { defineStore } from 'pinia'

export const useAudioStore = defineStore('audio', {
  state: () => ({
    currentPlayingId: null
  }),
  actions: {
    setPlaying(id) {
      if (this.currentPlayingId && this.currentPlayingId !== id) {
        // 通知上一个播放器暂停
        document.dispatchEvent(
          new CustomEvent('forcePause', {
            detail: { except: id }
          })
        )
      }
      this.currentPlayingId = id
    }
  }
})
